
package mongolo;
import Biblioteca.*;
import Servicios.*;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import com.toedter.calendar.*;
import javax.swing.JOptionPane;


public class ConsultaPelisAlquiladas extends javax.swing.JFrame {

    /** Creates new form ConsultaPelisAlquiladas */
    public ConsultaPelisAlquiladas() {
        initComponents();
        this.setDefaultCloseOperation(javax.swing.JFrame.HIDE_ON_CLOSE);
    }

    IMapeoObjetos mapo = new MapeoObjetos();

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        PeliculasAlquiladas_jTable = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowActivated(java.awt.event.WindowEvent evt) {
                formWindowActivated(evt);
            }
        });

        PeliculasAlquiladas_jTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(PeliculasAlquiladas_jTable);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 803, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(238, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    private boolean notYet = true;
    private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
        if (notYet) {
            notYet = false;
            try {
                String[] vecString = {"Nombre del Usuario","Nombre de la pelicula","Cant de peli. total",
                "Cant de peli. Alquiladas","Fecha de alquiler","Dias Alquilada","Fecha de vuelta"};
                DefaultTableModel ColumDTM = SM.crearFilasNecesarias(vecString);
                
                
                PeliculasAlquiladas_jTable.setModel(ColumDTM);


                TableColumn jDatePicker = PeliculasAlquiladas_jTable.getColumnModel().getColumn(6);
                jDatePicker.setCellEditor(new JDateChooserCellEditor());

                jDatePicker = PeliculasAlquiladas_jTable.getColumnModel().getColumn(4);
                jDatePicker.setCellEditor(new JDateChooserCellEditor());

                ArrayList<peliAquiladas> LispeliAquiladas = mapo.getpeliAquiladas(SM.getUsuaSelected().id);
                Object[] vec = new Object[7];
                for (peliAquiladas peliAquiladas : LispeliAquiladas) {
                    vec[0] = SM.ValidarNulls(peliAquiladas.nom_usua,"Error");
                    vec[1] = SM.ValidarNulls(peliAquiladas.nom_peli,"Error");
                    vec[2] = SM.ValidarNulls(peliAquiladas.cantPeliTotal,"Error");
                    vec[3] = SM.ValidarNulls(peliAquiladas.cantAlquiPelis,"Error");
                    vec[4] = SM.ValidarNulls(peliAquiladas.fechaAlqui,"Error");
                    vec[5] = SM.ValidarNulls(peliAquiladas.diasAlqui,"Error");
                    vec[6] = SM.ValidarNulls(peliAquiladas.fechaDevuelt,"Error");

                    ColumDTM.addRow(vec);
                    PeliculasAlquiladas_jTable.setModel(ColumDTM);
                    vec = new Object[7];
                }
                int i = 0;
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, "Ocurrio un error los datos no se pudieron cargar");
            }
        }
    }//GEN-LAST:event_formWindowActivated

    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable PeliculasAlquiladas_jTable;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
